package service

import (
	"gin/common"
	"gin/common/constant"
	"gin/common/db/config"
	util2 "gin/common/util"
	sysEntity "gin/system/entity"
	"github.com/gin-gonic/gin"
)


//表名称  提取
var tableName = "sys_dict_data"
//所有表字段提取
var sqlTitle ="dict_code as id" +","+ "dict_sort"+","+ "dict_label"+","+ "dict_value"+","+ "dict_type"+","+ "css_class"+","+"list_class"+","+ "is_default"+","+"status"+","+"create_by"+","+ "create_time"+","+ "remark"+","+"ct_id_p as idP"


/**
 * 数据字典键值信息
 *2024-11-18 09:08
 * @author wangwei
 */
func GetDictDataList(c *gin.Context) {
	resultList := make([]*sysEntity.SysDictData, 0)

	dictType := c.Query("dictType")

	dictDataErr := config.GormDb.Model(&sysEntity.DictType{}).Table("sys_dict_data").
		Select("ct_id_p", "dict_code", "dict_sort", "dict_label", "dict_value", "dict_type", "css_class",
			"list_class", "is_default", "status", "create_by", "create_time", "remark").
		Where("LOWER(dict_type) = LOWER(?)", dictType).Scan(&resultList).Error
	if dictDataErr != nil {
		common.ReturnError(c, constant.ERRORCODE(), constant.ERRORMSG()+",错误详细信息为： "+util2.MapToJson(dictDataErr), "", int64(len("")))
		panic("")
	}
	common.ReturnListSucess(c, constant.SUCCESSCODE(), constant.SUCCESSMSG(), resultList, int64(len(resultList)))
}



/***
根据字典类型查询字典数据
 */
func GetDictDataTypeList(c *gin.Context) {
	resultList := make([]*sysEntity.SysDictData, 0)
	dictType := c.Param("dictType")

	dictDataErr := config.GormDb.Model(&sysEntity.DictType{}).Table(tableName).Select(sqlTitle).
		Where("LOWER(dict_type) = LOWER(?)", dictType).Scan(&resultList).Error
	if dictDataErr != nil {
		common.ReturnError(c, constant.ERRORCODE(), constant.ERRORMSG()+",错误详细信息为： "+util2.MapToJson(dictDataErr), "", int64(len("")))
		panic("")
	}
	common.ReturnSucess(c, constant.SUCCESSCODE(), constant.SUCCESSMSG(), resultList, int64(len(resultList)))
}
